﻿using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class PierModelTablePloter
    {
        static string _dwgPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Template\\RebarGrade.dwg";
        static double rowH = 6;
        static bool isCopy = false;
        static string oldBlockName = "OneGrade";
        /// <summary>
        /// 承台钢筋明细表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="tbHeight"></param>
        /// <param name="tbWidth"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        ///  <param name="isHaveNetRebar">是否有钢筋网</param>
        public static void DrawCapRebarTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<int, eSampleType, eDB, int, double, string>> rebarLst, List<string> headName,
            int rowNum, int colNum, ref double tbHeight,ref double tbWidth, string txtStyle, double scale,string Grade= "HRB300", bool isHaveNetRebar = false,int netNum=2)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                //tb.SetColumnWidth(50);
                //tb.Width = tbWidth;
                //tb.Height = tbHeight;
             
                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 10 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (headName.Contains("大样"))
                    {
                        if (i < 2)
                            tb.Columns[i].Width = 10 * scale;
                        else if (i > 2)
                            tb.Columns[i].Width = 18 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                    else
                    {
                        if (i > 1)
                            tb.Columns[i].Width = 15 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                }
                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 10 * scale;
                }
                for (int i = 0; i < rebarLst.Count; i++)
                {
                    // 设置表数据    
                    string strNo = rebarLst[i].Item1.ToString();                                     // 钢筋编号
                    string strDiameter = "Ф"+ (int)rebarLst[i].Item3;                         // 直径
                    eSampleType strProbably_length = rebarLst[i].Item2;           // 大样
                    string strLength = rebarLst[i].Item5.ToString()+ "\r    ";                             // 单根长
                    string strNum = rebarLst[i].Item4.ToString();                                // 数量
                    string strTotal_length = (rebarLst[i].Item4 * rebarLst[i].Item5*0.01).ToString("0.0");                 // 总长
                    string strSingle_weight = GlobalFuncs.GetUnitWeight(rebarLst[i].Item3).ToString("0.000");               // 单重
                    string strTotal_weight =( GlobalFuncs.GetUnitWeight(rebarLst[i].Item3)* rebarLst[i].Item4 * rebarLst[i].Item5 * 0.01).ToString("0.0");                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_weight; //获取i行j列数据
   
                    }
                    string _blcName = "OneGrade";
                    //switch (rebarLst[i].Item6)
                    //{
                    //    //case "HRB300":

                    //    //    strDiameter= "%%130" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB335":

                    //    //    strDiameter = "%%131" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB400":

                    //    //    strDiameter = "%%132" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB500":

                    //    //    strDiameter = "%%133" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    case "HRB300":

                    //        strDiameter = "A" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB335":

                    //        strDiameter = "B" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB400":

                    //        strDiameter = "C" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB500":

                    //        strDiameter = "D" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB650E":

                    //        strDiameter = "D" + (int)rebarLst[i].Item3;
                    //        break;
                    //}
                    //if (rebarLst[i].Item6 != "DE")
                    //{
                    strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item3;
                    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    //}
                    //else
                    //{
                    //strDiameter = "  "+ (int)rebarLst[i].Item3;
                    //    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    //    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string blcName = "650";
                    //    string blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    }
                    //strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item3;
                    //Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    ////TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                //}

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("小计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        if (headName.Contains("大样"))
                        {
                            if (j > 2 && j != 4)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;                        
                        }
                        else
                        {
                            if (j > 1 && j != 3)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;
                        
                    }
                }



                #region 绘制大样
                if (headName.Contains("大样"))
                {
                    Point2d pt = tb.Position.C2D(tb.Columns[0].Width + tb.Columns[1].Width , -tb.Rows[0].Height);
                    for (int m = 0; m < rebarLst.Count; m++)
                    {
                        Tuple<int, eSampleType, eDB, int, double, string> valueTuple; ;
                        try
                        {
                            valueTuple = rebarLst[m];
                            if (valueTuple.Item2 == eSampleType.UN || valueTuple.Item2 == eSampleType.UT || valueTuple.Item2 == eSampleType.UB)
                            {     
                                if(valueTuple.Item2 != eSampleType.UN)                        
                                SteelBarPileCap.AddLineSample2Dim(db, pt.C2D(tb.Columns[2].Width*0.5, -tb.Rows[1].Height * 0.5 - tb.Rows[1].Height * (m)), ref ext, "H钢筋", valueTuple.Item3 , valueTuple.Item2, (valueTuple.Item5 - GeneralRebar.outerDiaHoke[valueTuple.Item3]*2).ToString(), 18 * scale, 2.5 *scale,0,scale,2.5,false);
                                else
                                    SteelBarPileCap.AddLineSample2Dim(db, pt.C2D(tb.Columns[2].Width * 0.5, -tb.Rows[1].Height * 0.5 - tb.Rows[1].Height * (m)), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, (valueTuple.Item5).ToString(), 18 * scale, 2.5 * scale, 0, scale, 2.5, false);
                            }

                        }
                        catch
                        {

                        }
                       
                    }
                }
                #endregion

                #region 列单元格合并
                if (headName.Contains("小计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = rebarLst[0].Item3.ToString();
                    for (int i = 0; i < rebarLst.Count; ++i)
                    {
                        if (rebarLst[i].Item3.ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = rebarLst[0].Item3.ToString();

                        }
                        if (i == rebarLst.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion


                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

            }
        }


        public static void DrawCapMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<int, eSampleType, eDB, int, double,  string>>  rebarLst, List<string> headName, int count, double volumn,double volumnCushion,
         int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, List<Tuple<eDB, double, double,string>> tuNet, double scale,string Grade= "HRB300", string MainGrade = "HRB300", string mainDB="", string concrete_no = "C35")
        {
            #region 数据合并
            // 数据合并
            Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
            for (int i = 0; i < rebarLst.Count; ++i)
            {
                string strNo = rebarLst[i].Item3.ToString();
                if (dic.Count == 0)
                {
                    List<int> list = new List<int>();
                    list.Add(i);
                    dic.Add(strNo, list);
                }
                else
                {
                    if (!dic.ContainsKey(strNo))
                    {
                        List<int> list = new List<int>();
                        list.Add(i);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        List<int> list = new List<int>();
                        dic.TryGetValue(strNo, out list);
                        list.Add(i);
                        dic[strNo] = list;
                    }
                }
            }
            //dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
            #endregion
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                int rowNum = 1 + dic.Count + 2+tuNet.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 0)
                        tb.MergeCells(CellRange.Create(tb, 0, 0, 0, 1));
                }
                tb.Rows[0].Height = 8 * scale;

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i==4)
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                    else if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 12 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }
                #region 表格添加数据
                int index = 0;
                double allWeight = 0;
                //int netCount = tuNet.Count;
                foreach (KeyValuePair<string, List<int>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    // 设置表数据
                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = rebarLst[pr.Value[i]].Item3;                         // 直径
                        totallength += rebarLst[pr.Value[i]].Item4 * rebarLst[pr.Value[i]].Item5 ;

                    }
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.01 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    tb.Cells[index + 1, 1].TextString = "Ф" + (int)diameter; //获取i行j列数据
                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight * count).ToString("0.0"); //获取i行j列数据   
                    allWeight += totalWeight * count;
                    string strDiameter = "Ф" + (int)diameter;
                    switch (Grade)
                    {

                        case "HRB300":
                            strDiameter = "A" + (int)diameter;
                            break;
                        case "HRB335":
                            strDiameter = "B" + (int)diameter;
                            break;
                        case "HRB400":
                            strDiameter = "C" + (int)diameter;
                            break;
                        case "HRB500":
                            strDiameter = "D" + (int)diameter;
                            break;
                        case "HRB500E":
                            strDiameter = "E" + (int)diameter;
                            break;
                        case "HRB650E":
                            strDiameter = "F" + (int)diameter;
                            break;
                        case "HRB700":
                            strDiameter = "G" + (int)diameter;
                            break;
                    }
                    string strMainDiameter = "D";
                    switch (MainGrade)
                    {

                        case "HRB300":
                            strMainDiameter = "A";
                            break;
                        case "HRB335":
                            strMainDiameter = "B";
                            break;
                        case "HRB400":
                            strMainDiameter = "C";
                            break;
                        case "HRB500":
                            strMainDiameter = "D";
                            break;
                        case "HRB500E":
                            strMainDiameter = "E";
                            break;
                        case "HRB650E":
                            strMainDiameter = "F";
                            break;
                        case "HRB700":
                            strMainDiameter = "G";
                            break;
                        default:
                            strMainDiameter = "D";
                            break;
                    }
                    //if (mainDB.ToString().Contains(diameter.ToString())&& MainGrade== "HRB650E")
                    if (mainDB.ToString().Contains(diameter.ToString()))
                    {
                        strDiameter = strMainDiameter + (int)diameter;
                        tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                        //string path = Extensions.curAppPath + "HRB650E.dwg";
                        ////string _blcName = "650";
                        //string _blcName = "HRB650E";
                        //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    }
                    else
                    {
                        tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    }
                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, 1, 0, dic.Count, 0));
                tb.MergeCells(CellRange.Create(tb, 1, 2, dic.Count, 2));
                tb.Cells[1, 4].TextString = allWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, dic.Count, 4));

                index = dic.Count;
                double  allWeightNet = 0;
                int netCount = tuNet.Count;
                foreach (Tuple<eDB, double, double, string> item in tuNet)
                {
                    string strNo = "焊接钢筋网";
                    string unit = "kg";
                    eDB diameter = eDB.None;
     
                    double weight = GlobalFuncs.GetUnitAreaWeight(item.Item1,item.Item3)*1.1;
                    double totalWeight = item.Item2 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    tb.Cells[index + 1, 1].TextString = "Ф" + (int)diameter; //获取i行j列数据
                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight * count).ToString("0.0"); //获取i行j列数据   
                    allWeightNet += totalWeight * count;


                    tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                    TextPloter.AddDBText(db,ptGJGrade, ref ext, item.Item4+(int)item.Item1, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, dic.Count + 1, 0, dic.Count + tuNet.Count, 0));
                tb.MergeCells(CellRange.Create(tb, dic.Count + 1, 2, dic.Count + tuNet.Count, 2));
                tb.Cells[dic.Count + 1, 4].TextString = allWeightNet.ToString("0.0"); //获取i行j列数据
                tb.Cells[dic.Count + 1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[dic.Count + 1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 4].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[dic.Count + 1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, dic.Count + 1, 4, dic.Count+ tuNet.Count, 4));





                //tb.Cells[1 + dic.Count, 0].TextString = "绑扎铁丝(0.5%)"; //获取i行j列数据
                //tb.Cells[1 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[1 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[1 + dic.Count, 0].Contents[0].Rotation = 0;
                //tb.Cells[1 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[1 + dic.Count, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 0, 1 + dic.Count, 1));

                //tb.Cells[1 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                //tb.Cells[1 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[1 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[1 + dic.Count, 2].Contents[0].Rotation = 0;
                //tb.Cells[1 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[1 + dic.Count, 2].Contents[0].TextStyleId = id;


                //tb.Cells[1 + dic.Count, 3].TextString = (allWeight * 0.005).ToString("0.0"); //获取i行j列数据
                //tb.Cells[1 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[1 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[1 + dic.Count, 3].Contents[0].Rotation = 0;
                //tb.Cells[1 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[1 + dic.Count, 3].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));

                tb.Cells[1 + dic.Count+tuNet.Count, 0].TextString = "混凝土"; //获取i行j列数据
                tb.Cells[1 + dic.Count+tuNet.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count+tuNet.Count, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count+tuNet.Count, 0].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count+tuNet.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count+ tuNet.Count, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1 + dic.Count+ tuNet.Count, 0, 2 + dic.Count+ tuNet.Count, 0));

                tb.Cells[1 + dic.Count+tuNet.Count, 1].TextString = concrete_no; //获取i行j列数据
                tb.Cells[1 + dic.Count+tuNet.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count+tuNet.Count, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count+tuNet.Count, 1].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count+tuNet.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count+ tuNet.Count, 1].Contents[0].TextStyleId = id;

                tb.Cells[1 + dic.Count+tuNet.Count, 2].TextString = "m³"; //获取i行j列数据
                tb.Cells[1 + dic.Count+tuNet.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count+tuNet.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count+tuNet.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count+tuNet.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count+ tuNet.Count, 2].Contents[0].TextStyleId = id;


                tb.Cells[1 + dic.Count+tuNet.Count, 3].TextString = (count * volumn).ToString("0.0"); //获取i行j列数据
                tb.Cells[1 + dic.Count+tuNet.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count+tuNet.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count+tuNet.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count+tuNet.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count+ tuNet.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1 + dic.Count+ tuNet.Count, 3, 1 + dic.Count+ tuNet.Count, 4));

                //tb.Cells[2 + dic.Count, 0].TextString = "垫层"; //获取i行j列数据
                //tb.Cells[2 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[2 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[2 + dic.Count, 0].Contents[0].Rotation = 0;
                //tb.Cells[2 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[2 + dic.Count, 0].Contents[0].TextStyleId = id;


                tb.Cells[2 + dic.Count+tuNet.Count, 1].TextString = "C15"; //获取i行j列数据
                tb.Cells[2 + dic.Count+tuNet.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count+tuNet.Count, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count+tuNet.Count, 1].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count+tuNet.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count+ tuNet.Count, 1].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 3 + dic.Count, 0, 3 + dic.Count, 1));

                tb.Cells[2 + dic.Count+tuNet.Count, 2].TextString = "m³"; //获取i行j列数据
                tb.Cells[2 + dic.Count+tuNet.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count+tuNet.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count+tuNet.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count+tuNet.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count+ tuNet.Count, 2].Contents[0].TextStyleId = id;


                tb.Cells[2 + dic.Count+tuNet.Count, 3].TextString = (count * volumnCushion).ToString("0.0"); //获取i行j列数据
                tb.Cells[2 + dic.Count+tuNet.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count+tuNet.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count+tuNet.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count+tuNet.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count+ tuNet.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2 + dic.Count+ tuNet.Count, 3, 2 + dic.Count+ tuNet.Count, 4));
                #endregion

                

                #region 列单元格合并

                #endregion
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }


        
        public static void DrawCushionRebarTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<int, eSampleType, eDB, int, double, string>> rebarLst, List<string> headName,
            int rowNum, int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale, string Grade = "HRB300", bool isHaveNetRebar = false, int netNum = 2)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                //tb.SetColumnWidth(50);
                //tb.Width = tbWidth;
                //tb.Height = tbHeight;

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 10 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (headName.Contains("大样"))
                    {
                        if (i < 2)
                            tb.Columns[i].Width = 10 * scale;
                        else if (i > 2)
                            tb.Columns[i].Width = 18 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                    else
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 10 * scale;
                        else
                            tb.Columns[i].Width = 15 * scale;
                    }
                }
                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 10 * scale;
                }
                for (int i = 0; i < rebarLst.Count; i++)
                {
                    // 设置表数据    
                    string strNo = rebarLst[i].Item1.ToString();                                     // 钢筋编号
                    string strDiameter = "Ф" + (int)rebarLst[i].Item3;                         // 直径
                    eSampleType strProbably_length = rebarLst[i].Item2;           // 大样
                    string strLength = rebarLst[i].Item5.ToString("0") + "\r    ";                             // 单根长
                    string strNum = rebarLst[i].Item4.ToString();                                // 数量
                    string strTotal_length = (rebarLst[i].Item4 * rebarLst[i].Item5 * 0.001).ToString("0");                 // 总长
                    string strSingle_weight = GlobalFuncs.GetUnitWeight(rebarLst[i].Item3).ToString("0.000");               // 单重
                    string strTotal_weight = (GlobalFuncs.GetUnitWeight(rebarLst[i].Item3) * rebarLst[i].Item4 * rebarLst[i].Item5 * 0.01).ToString("0.0");                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_weight; //获取i行j列数据

                    }
                    string _blcName = "OneGrade";
                    //switch (rebarLst[i].Item6)
                    //{
                    //    //case "HRB300":

                    //    //    strDiameter= "%%130" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB335":

                    //    //    strDiameter = "%%131" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB400":

                    //    //    strDiameter = "%%132" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    //case "HRB500":

                    //    //    strDiameter = "%%133" + (int)rebarLst[i].Item3;
                    //    //    break;
                    //    case "HRB300":

                    //        strDiameter = "A" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB335":

                    //        strDiameter = "B" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB400":

                    //        strDiameter = "C" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB500":

                    //        strDiameter = "D" + (int)rebarLst[i].Item3;
                    //        break;
                    //    case "HRB650E":

                    //        strDiameter = "D" + (int)rebarLst[i].Item3;
                    //        break;
                    //}
                    //if (rebarLst[i].Item6 != "DE")
                    //{
                    strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item3;
                    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    TextPloter.AddDBText(db, ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    //}
                    //else
                    //{
                    //strDiameter = "  "+ (int)rebarLst[i].Item3;
                    //    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    //    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string blcName = "650";
                    //    string blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                }
                //strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item3;
                //Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                ////TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                //}

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("小计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        if (headName.Contains("大样"))
                        {
                            if (j > 2 && j != 4)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        else
                        {
                            if (j > 1 && j != 3)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;

                    }
                }



                #region 绘制大样
                if (headName.Contains("大样"))
                {
                    Point2d pt = tb.Position.C2D(tb.Columns[0].Width + tb.Columns[1].Width, -tb.Rows[0].Height);
                    for (int m = 0; m < rebarLst.Count; m++)
                    {
                        Tuple<int, eSampleType, eDB, int, double, string> valueTuple; ;
                        try
                        {
                            valueTuple = rebarLst[m];
                            if (valueTuple.Item2 == eSampleType.UN || valueTuple.Item2 == eSampleType.UT || valueTuple.Item2 == eSampleType.UB)
                            {
                                if (valueTuple.Item2 != eSampleType.UN)
                                    SteelBarPileCap.AddLineSample2Dim(db, pt.C2D(tb.Columns[2].Width * 0.5, -tb.Rows[1].Height * 0.5 - tb.Rows[1].Height * (m)), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, (valueTuple.Item5 - GeneralRebar.outerDiaHoke[valueTuple.Item3] * 2).ToString(), 18 * scale, 2.5 * scale, 0, scale, 2.5, false);
                                else
                                    SteelBarPileCap.AddLineSample2Dim(db, pt.C2D(tb.Columns[2].Width * 0.5, -tb.Rows[1].Height * 0.5 - tb.Rows[1].Height * (m)), ref ext, "H钢筋", valueTuple.Item3, valueTuple.Item2, (valueTuple.Item5).ToString(), 18 * scale, 2.5 * scale, 0, scale, 2.5, false);
                            }

                        }
                        catch
                        {

                        }

                    }
                }
                #endregion

                #region 列单元格合并
                if (headName.Contains("小计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = rebarLst[0].Item3.ToString();
                    for (int i = 0; i < rebarLst.Count; ++i)
                    {
                        if (rebarLst[i].Item3.ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = rebarLst[0].Item3.ToString();

                        }
                        if (i == rebarLst.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion


                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

            }
        }


        public static void DrawCushionMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<int, eSampleType, eDB, int, double, string>> rebarLst, List<string> headName, int count, double volumn, 
   int colNum, ref double tbHeight, ref double tbWidth, string txtStyle,  double scale, string Grade = "HRB300", string concrete_no = "C35")
        {
            #region 数据合并
            // 数据合并
            Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
            for (int i = 0; i < rebarLst.Count; ++i)
            {
                string strNo = rebarLst[i].Item3.ToString();
                if (dic.Count == 0)
                {
                    List<int> list = new List<int>();
                    list.Add(i);
                    dic.Add(strNo, list);
                }
                else
                {
                    if (!dic.ContainsKey(strNo))
                    {
                        List<int> list = new List<int>();
                        list.Add(i);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        List<int> list = new List<int>();
                        dic.TryGetValue(strNo, out list);
                        list.Add(i);
                        dic[strNo] = list;
                    }
                }
            }
            //dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
            #endregion
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                int rowNum = 1 + dic.Count +1;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 0)
                        tb.MergeCells(CellRange.Create(tb, 0, 0, 0, 1));
                }
                tb.Rows[0].Height = 8 * scale;

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 4)
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                    else if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 12 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }
                #region 表格添加数据
                int index = 0;
                double allWeight = 0;
                //int netCount = tuNet.Count;
                foreach (KeyValuePair<string, List<int>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    // 设置表数据
                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = rebarLst[pr.Value[i]].Item3;                         // 直径
                        totallength += rebarLst[pr.Value[i]].Item4 * rebarLst[pr.Value[i]].Item5;

                    }
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.001 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    tb.Cells[index + 1, 1].TextString = "Ф" + (int)diameter; //获取i行j列数据
                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight * count).ToString("0.0"); //获取i行j列数据   
                    allWeight += totalWeight * count;
                    string strDiameter = "Ф" + (int)diameter;
                    switch (Grade)
                    {

                        case "HRB300":
                            strDiameter = "A" + (int)diameter;
                            break;
                        case "HRB335":
                            strDiameter = "B" + (int)diameter;
                            break;
                        case "HRB400":
                            strDiameter = "C" + (int)diameter;
                            break;
                        case "HRB500":
                            strDiameter = "D" + (int)diameter;
                            break;
                        case "HRB500E":
                            strDiameter = "E" + (int)diameter;
                            break;
                        case "HRB650E":
                            strDiameter = "F" + (int)diameter;
                            break;
                        case "HRB700":
                            strDiameter = "G" + (int)diameter;
                            break;
                    }


                    tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                    TextPloter.AddDBText(db, ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, 1, 0, dic.Count, 0));
                tb.MergeCells(CellRange.Create(tb, 1, 2, dic.Count, 2));
                tb.Cells[1, 4].TextString = allWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, dic.Count, 4));

                index = dic.Count;
               

                tb.Cells[1 + dic.Count , 0].TextString = "混凝土"; //获取i行j列数据
                tb.Cells[1 + dic.Count , 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count , 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count , 0].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count , 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count , 0].Contents[0].TextStyleId = id;
                                       
                tb.Cells[1 + dic.Count , 1].TextString = concrete_no; //获取i行j列数据
                tb.Cells[1 + dic.Count , 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count , 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count , 1].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count , 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count , 1].Contents[0].TextStyleId = id;
                                       
                tb.Cells[1 + dic.Count , 2].TextString = "m³"; //获取i行j列数据
                tb.Cells[1 + dic.Count , 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count , 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count , 2].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count , 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count , 2].Contents[0].TextStyleId = id;
                                       
                                       
                tb.Cells[1 + dic.Count , 3].TextString = (count * volumn).ToString("0.0"); //获取i行j列数据
                tb.Cells[1 + dic.Count , 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count , 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count , 3].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count , 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count , 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));

         
                #endregion



                #region 列单元格合并

                #endregion
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }

        /// <summary>
        /// 材料数量明细表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="dt"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="tbHeight"></param>
        /// <param name="tbWidth"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        public static void DrawCapMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double,string>>, int, string>> tuLst, List<string> headName, 
            int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale)
        {
            #region 数据合并
            // 数据合并
            Dictionary<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>> dic = new Dictionary<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>>();
            foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
            {
                List<Tuple<int, Tuple<string, eDB, int, double, string>>> list = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>();
                for (int i = 0; i < item.Item2.Count; ++i)
                {
                    eDB strNo = item.Item2[i].Item2;
                    if (dic.Count == 0)
                    {
                        Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                        list.Add(tu);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        if (!dic.ContainsKey(strNo))
                        {
                            list = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>();
                            Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                            list.Add(tu);
                            dic.Add(strNo, list);
                        }
                        else
                        {
                            List<Tuple<int, Tuple<string, eDB, int, double, string>>> lstDB = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>(); ;
                            dic.TryGetValue(strNo, out lstDB);
                            Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                            lstDB.Add(tu);
                            dic[strNo] = lstDB;
                        }
                    }
                }
            }
            dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
            #endregion
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                int rowNum = 1 + dic.Count + 3;
                if (tuLst[0].Item1.is_add_steel_casing == "1")
                {
                    rowNum += 3;
                }
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 0)
                        tb.MergeCells(CellRange.Create(tb, 0, 0, 0, 1));
                }
                tb.Rows[0].Height = 8 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 22 * scale;
                    }
                    else if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 12 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 22 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }


                #region 表格添加数据
                int index = 0;
                double allWeight = 0;
                foreach (KeyValuePair<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    // 设置表数据

                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = pr.Key;                         // 直径
                        totallength += pr.Value[i].Item1 * (pr.Value[i].Item2.Item3 * pr.Value[i].Item2.Item4);

                    }
                    string strMainDiameter = "D";
                    switch (tuLst[0].Item1.main_reinforcement_grade)
                    {

                        case "HRB300":
                            strMainDiameter = "A";
                            break;
                        case "HRB335":
                            strMainDiameter = "B";
                            break;
                        case "HRB400":
                            strMainDiameter = "C";
                            break;
                        case "HRB500":
                            strMainDiameter = "D";
                            break;
                        case "HRB500E":
                            strMainDiameter = "E";
                            break;
                        case "HRB650E":
                            strMainDiameter = "F";
                            break;
                        case "HRB700":
                            strMainDiameter = "G";
                            break;
                        default:
                            strMainDiameter = "D";
                            break;
                    }
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.01 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    string vdia = "Ф" + (int)diameter;
                    //if (pr.Key != tuLst[0].Item1.spiral_reinforcement_diameter)
                    //{
                    tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                    if (pr.Key == tuLst[0].Item1.main_reinforcement_diameter)
                    {
                        vdia = strMainDiameter + (int)diameter;
                        //vdia = "  " + (int)diameter;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, vdia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                        //    string path = Extensions.curAppPath + "HRB650E.dwg";
                        //    //string _blcName = "650";
                        //string _blcName = "HRB650E";
                        //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale*0.85, 0, true, false);
                    }
                    else
                    {
                        vdia = tuLst[0].Item4 + (int)diameter;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, vdia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    }



                    //}
                    //else
                    //{
                    //    tb.Cells[index + 1, 1].TextString = "Ф" + (int)diameter; //获取i行j列数据
                    //}

                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight).ToString("0.0"); //获取i行j列数据   
                    allWeight += totalWeight;
                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, 1, 0, dic.Count, 0));
                tb.MergeCells(CellRange.Create(tb, 1, 2, dic.Count, 2));
                tb.Cells[1, 4].TextString = allWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, dic.Count, 4));

                tb.Cells[1 + dic.Count, 0].TextString = "钢筋连接器"; //获取i行j列数据
                tb.Cells[1 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 0].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 0].Contents[0].TextStyleId = id;

                tb.Cells[1 + dic.Count, 1].TextString = " "; //获取i行j列数据
                tb.Cells[1 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 1].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 1].Contents[0].TextStyleId = id;
                string maindia = tuLst[0].Item4 + (int)tuLst[0].Item1.main_reinforcement_diameter;
                string strDiameter = "D";
                switch (tuLst[0].Item1.main_reinforcement_grade)
                {

                    case "HRB300":
                        strDiameter = "A";
                        break;
                    case "HRB335":
                        strDiameter = "B";
                        break;
                    case "HRB400":
                        strDiameter = "C";
                        break;
                    case "HRB500":
                        strDiameter = "D";
                        break;
                    case "HRB500E":
                        strDiameter = "E";
                        break;
                    case "HRB650E":
                        strDiameter = "F";
                        break;
                    case "HRB700":
                        strDiameter = "G";
                        break;
                    default:
                        strDiameter = "D";
                        break;
                }
                //if (tuLst[0].Item1.main_reinforcement_grade != "HRB650E")
                //{
                maindia = strDiameter + (int)tuLst[0].Item1.main_reinforcement_diameter;
                Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                //}
                //else
                //{
                //    maindia = "  " + (int)tuLst[0].Item1.main_reinforcement_diameter;
                //    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                //    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                //    string path = Extensions.curAppPath + "HRB650E.dwg";
                //    //string _blcName = "650";
                //    string _blcName = "HRB650E";
                //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptMainGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                //}

                tb.Cells[1 + dic.Count, 2].TextString = "套"; //获取i行j列数据
                tb.Cells[1 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 2].Contents[0].TextStyleId = id;

                double volumnAll = 0; //混凝土体积
                int totalCap = 0; //钢筋连接器数量
                double weightTubee = 0; //声测管重量
                foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
                {
                    double tH = Math.Abs(double.Parse(item.Item1.top_size.Split('*')[0]));
                    double tL = Math.Abs(double.Parse(item.Item1.top_size.Split('*')[1]));
                    double bH = Math.Abs(double.Parse(item.Item1.bottom_size.Split('*')[0]));
                    double bL = Math.Abs(double.Parse(item.Item1.bottom_size.Split('*')[1]));
                    double volumn = Math.Round((item.Item1.pile_length * 0.01- tH * 0.01- bH * 0.01) * Math.PI * item.Item1.pile_diameter * 0.5 * 0.01 * item.Item1.pile_diameter * 0.5 * 0.01,2);
                    double dia1 = item.Item1.pile_diameter * 0.5 * 0.01;
                    double dia2 = item.Item1.pile_diameter * 0.5 * 0.01+ tL*0.01;
                    double volumn2 = Math.Ceiling(tH * 0.01 * Math.PI * (dia1 + dia2)*0.5 * (dia1 + dia2) * 0.5);
                    dia1 = item.Item1.pile_diameter * 0.5 * 0.01;
                    dia2 = Math.Round(item.Item1.pile_diameter * 0.5 * 0.01 - bL * 0.01,1);
                    double volumn3 = Math.Ceiling(bH * 0.01 * Math.PI * (dia1 + dia2) * 0.5 * (dia1 + dia2) * 0.5);
                    //double volumn4 = Math.Round(bH * 0.01 * Math.PI * (dia1)  * (dia1), 2);
                    volumnAll += (volumn+ volumn2+ volumn3) * item.Item3;
                    totalCap += ((int)(item.Item1.pile_length * 0.01 / 9)) * item.Item1.main_reinforcement_number * item.Item3;
                    string tubetype = item.Item1.acoustic_tube_type;
                    double outDia = double.Parse(tubetype.Split('*')[0]);
                    double thinessDia = double.Parse(tubetype.Split('*')[1]);
                    weightTubee += 0.02466 * thinessDia * (outDia - thinessDia) * (item.Item1.pile_length * 0.01 + item.Item1.acoustic_tube_length * 0.01) * item.Item1.acoustic_tube_number * item.Item1.structure_number;
                }


                tb.Cells[1 + dic.Count, 3].TextString = (totalCap).ToString(); //获取i行j列数据
                tb.Cells[1 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));


                //tb.Cells[2 + dic.Count, 0].TextString = "绑扎铁丝(0.5%)"; //获取i行j列数据
                //tb.Cells[2 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[2 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[2 + dic.Count, 0].Contents[0].Rotation = 0;
                //tb.Cells[2 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[2 + dic.Count, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 0, 2 + dic.Count, 1));

                //tb.Cells[2 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                //tb.Cells[2 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[2 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[2 + dic.Count, 2].Contents[0].Rotation = 0;
                //tb.Cells[2 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[2 + dic.Count, 2].Contents[0].TextStyleId = id;


                //tb.Cells[2 + dic.Count, 3].TextString = (allWeight * 0.005).ToString("0.0"); //获取i行j列数据
                //tb.Cells[2 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[2 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[2 + dic.Count, 3].Contents[0].Rotation = 0;
                //tb.Cells[2 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[2 + dic.Count, 3].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 3, 2 + dic.Count, 4));


                tb.Cells[2 + dic.Count, 0].TextString = "声测管Ф" + tuLst[0].Item1.acoustic_tube_type.Replace("*", "×"); //获取i行j列数据
                tb.Cells[2 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count, 0].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 0, 2 + dic.Count, 1));

                tb.Cells[2 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                tb.Cells[2 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count, 2].Contents[0].TextStyleId = id;


                tb.Cells[2 + dic.Count, 3].TextString = (weightTubee).ToString("0.0"); //获取i行j列数据
                tb.Cells[2 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2 + dic.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[2 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[2 + dic.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 3, 2 + dic.Count, 4));

                tb.Cells[3 + dic.Count, 0].TextString = "水下混凝土"; //获取i行j列数据
                tb.Cells[3 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3 + dic.Count, 0].Contents[0].Rotation = 0;
                tb.Cells[3 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[3 + dic.Count, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                tb.Cells[3 + dic.Count, 1].TextString = tuLst[0].Item1.concrete_no; //获取i行j列数据
                tb.Cells[3 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3 + dic.Count, 1].Contents[0].Rotation = 0;
                tb.Cells[3 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[3 + dic.Count, 1].Contents[0].TextStyleId = id;

                tb.Cells[3 + dic.Count, 2].TextString = "m³"; //获取i行j列数据
                tb.Cells[3 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3 + dic.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[3 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[3 + dic.Count, 2].Contents[0].TextStyleId = id;


                tb.Cells[3 + dic.Count, 3].TextString = (volumnAll).ToString("0.0"); //获取i行j列数据
                tb.Cells[3 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3 + dic.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[3 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[3 + dic.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3 + dic.Count, 3, 3 + dic.Count, 4));
                #endregion
                if (tuLst[0].Item1.is_add_steel_casing == "1")
                {
                    double dia = tuLst[0].Item1.pile_diameter * 10;
                    double dia1= tuLst[0].Item1.pile_diameter * 10+ tuLst[0].Item1.steel_casing_thickness*10*2;
                    double th = tuLst[0].Item1.steel_casing_thickness * 10;
                    double len = tuLst[0].Item1.steel_casing_length;
                    double weight = Math.PI * (Math.Pow(dia1 * 0.001 * 0.5, 2) - Math.Pow(dia * 0.001 * 0.5, 2)) * len*7850 * tuLst[0].Item1.structure_number;
                    tb.Cells[4 + dic.Count, 0].TextString = "钢管Ф" +dia1+ "×"+ th; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[4 + dic.Count, 1].TextString = "Q235C"; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[4 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 2].Contents[0].TextStyleId = id;

                    tb.Cells[4 + dic.Count, 3].TextString = (weight).ToString("0.0"); //获取i行j列数据
                    tb.Cells[4 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 3, 4 + dic.Count, 4));

                    if (tuLst[0].Item1.pile_length * 0.01 <= 20)
                        tb.Cells[5 + dic.Count, 0].TextString = "钢板φ1000×30"; //获取i行j列数据
                    else
                        tb.Cells[5 + dic.Count, 0].TextString = "钢板φ1200×50"; //获取i行j列数据
                    tb.Cells[5 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[5 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[5 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[5 + dic.Count, 1].TextString = "Q235C"; //获取i行j列数据
                    tb.Cells[5 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[5 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[5 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[5 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                    tb.Cells[5 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[5 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[5 + dic.Count, 2].Contents[0].TextStyleId = id;

                    if (tuLst[0].Item1.pile_length * 0.01 <= 20)
                        weight = Math.PI * (Math.Pow(1000 * 0.001 * 0.5, 2)- Math.Pow(700 * 0.001 * 0.5, 2)) * 30 * 0.001 * 7850 * tuLst[0].Item1.structure_number;
                    else
                        weight = Math.PI * (Math.Pow(1200 * 0.001 * 0.5, 2) - Math.Pow(800 * 0.001 * 0.5, 2)) * 50 * 0.001 * 7850 * tuLst[0].Item1.structure_number;
                   
                    tb.Cells[5 + dic.Count, 3].TextString = (weight).ToString("0.0"); //获取i行j列数据
                    tb.Cells[5 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[5 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[5 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 5 + dic.Count, 3, 5 + dic.Count, 4));

                  
                    tb.Cells[6 + dic.Count, 0].TextString = "锚栓M48×2000"; //获取i行j列数据
                    tb.Cells[6 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[6 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[6 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[6 + dic.Count, 1].TextString = "10.9级"; //获取i行j列数据
                    tb.Cells[6 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[6 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[6 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[6 + dic.Count, 2].TextString = "套"; //获取i行j列数据
                    tb.Cells[6 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[6 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[6 + dic.Count, 2].Contents[0].TextStyleId = id;

                    weight = 16 * tuLst[0].Item1.structure_number;
                    tb.Cells[6 + dic.Count, 3].TextString = (weight).ToString(); //获取i行j列数据
                    tb.Cells[6 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[6 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[6 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6 + dic.Count, 3, 6 + dic.Count, 4));
                }


                #region 列单元格合并

                #endregion
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }


        public static void DrawPileCalTable(Database db, ref Extents2d ext, Point3d startPoint, List<string> headName,
        ref double tbHeight, ref double tbWidth, string txtStyle, double scale, List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>> tuLst,bool isChange=false)
        {
            int colNum = headName.Count;
            int numR = 0;
            foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
            {
                numR += item.Item2.Count;
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                int rowNum = numR + 1;
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 设置列宽,行高

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 1 || i == 9)
                        tb.Columns[i].Width = 6 * 2.5 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 5 * 2.5 * scale;
                    else if (i == 8)
                        tb.Columns[i].Width = 12 * 2.5 * scale;
                    else if (i == 4)
                        tb.Columns[i].Width = 8 * 2.5 * scale;
                    else
                        tb.Columns[i].Width = 10 * 2.5 * scale;
                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if (i == 0)
                        tb.Rows[i].Height = 12 * scale;
                    else
                    {
                        if (numR > 5)
                            tb.Rows[i].Height = 6.3 * scale;
                        else
                            tb.Rows[i].Height = 8 * scale;
                    }
                }
                #endregion
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                int m = 1;
                foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
                {
                    foreach (Tuple<string, eDB, int, double, string> valueTuple in item.Item2)
                    {
                        try
                        {
                            string value = " ";
                            double dia = (int)(valueTuple.Item2);
                            for (int i = 0; i < colNum; ++i)
                            {
                                double weight = GlobalFuncs.GetUnitWeight(valueTuple.Item2);
                                double totalLength = valueTuple.Item3 * valueTuple.Item4 * 0.01;
                                switch (i)
                                {
                                    case 0:
                                        value = item.Item1.pile_length.ToString();
                                        break;
                                    case 1:
                                        value = valueTuple.Item1.ToString();
                                        break;
                                    case 2:
                                        value = "Ф" + dia.ToString();
                                        break;
                                    case 3:
                                        if (valueTuple.Item1 == "3"&& isChange)
                                            value = "均" + valueTuple.Item4.ToString("0.0");
                                        else
                                            value = valueTuple.Item4.ToString("0.0");
                                        break;
                                    case 4:
                                        value = valueTuple.Item3.ToString();
                                        break;
                                    case 5:
                                        value = totalLength.ToString("0.0");
                                        break;
                                    case 6:
                                        value = weight.ToString("0.000");
                                        break;
                                    case 7:
                                        value = (totalLength * weight).ToString("0.0");
                                        break;
          
                                }
                                if (i < 8)
                                {
                                    if (i != 2)
                                    {
                                        tb.Cells[m, i].TextString = value; //获取i行j列数据
                                        tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                        tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m, i].Contents[0].Rotation = 0;
                                        tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m, i].Contents[0].TextStyleId = id;
                                    }
                                    else
                                    {
                                        //if (valueTuple.Item2 == item.Item1.spiral_reinforcement_diameter)
                                        //{
                                        //    tb.Cells[m, i].TextString = value; //获取i行j列数据
                                        //}
                                        //else
                                        //{
                                            tb.Cells[m, i].TextString = " "; //获取i行j列数据
                                            if (valueTuple.Item5 != "DE")
                                            {
                                                Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width + tb.Columns[2].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * (m - 1) - tb.Rows[1].Height * 0.5);
                                                //if (valueTuple.Item2 == item.Item1.main_reinforcement_diameter)
                                                //{                                            
                                                //    value = valueTuple.Item5 + dia.ToString();
                                                //}
                                                //else
                                                //{
                                                //    value = item.Item4 + dia.ToString();
                                                //}
                                                value = valueTuple.Item5 + dia.ToString();
                                                TextPloter.AddDBText(db,ptGJGrade, ref ext, value, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                                            }
                                            else
                                            {
                                                Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width + tb.Columns[2].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * (m - 1) - tb.Rows[1].Height * 0.5);
                        
                                                value = "  " + dia.ToString();
                                                TextPloter.AddDBText(db,ptGJGrade, ref ext, value, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                                                string path = Extensions.curAppPath + "HRB650E.dwg";
                                                //string _blcName = "650";
                                            string _blcName = "HRB650E";
                                            BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                                            }
                                        //}
                                        tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                        tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m, i].Contents[0].Rotation = 0;
                                        tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m, i].Contents[0].TextStyleId = id;
                                       
                                    }
                                }
                                else
                                {
                                    if (m == 2)
                                    {
                                        tb.Cells[m, i].TextString = value; //获取i行j列数据
                                        tb.Cells[m, i].Contents[0].TextHeight = 2.5 * scale;
                                        tb.Cells[m, i].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m, i].Contents[0].Rotation = 0;
                                        tb.Cells[m, i].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m, i].Contents[0].TextStyleId = id;
                                        tb.MergeCells(CellRange.Create(tb, m, i, rowNum - 1, i));
                                    }
                                }
                            }
                            m++;
                        }
                        catch { }
                      
                    }
                    tb.MergeCells(CellRange.Create(tb, m -item.Item2.Count, 0, m - 1, 0));
                }

      

                tb.LayerId = lt["H细线"];
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }



        #region 盖梁量表
        public static void DrawBeamRebarTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<string,  eDB, int, double,string, string>> rebarLst, List<string> headName,
    int rowNum, int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale, string Grade = "HRB300", double volum = 0, string con = "C40混凝土(m³)")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                //tb.SetColumnWidth(50);
                //tb.Width = tbWidth;
                //tb.Height = tbHeight;

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 12 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                     if (i==2)
                        tb.Columns[i].Width = 20 * scale;
                    else if (i<2)
                        tb.Columns[i].Width = 15 * scale;
                   
                    else
                        tb.Columns[i].Width = 20 * scale;

                }
                rowH = 7 ;
                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 7 * scale;
                }
                for (int i = 0; i < rebarLst.Count; i++)
                {
                    // 设置表数据    
                    string strNo = rebarLst[i].Item1.ToString();                                     // 钢筋编号
                    string strDiameter = "Ф" + (int)rebarLst[i].Item2;                         // 直径
              
                    string strLength = rebarLst[i].Item5.ToString() + "\r    ";                             // 单根长
                    string strNum = rebarLst[i].Item3.ToString();                                // 数量
                    string strTotal_length = (rebarLst[i].Item4 * rebarLst[i].Item3 * 0.01).ToString("0.0");                 // 总长
                    string strSingle_weight = GlobalFuncs.GetUnitWeight(rebarLst[i].Item2).ToString("0.000");               // 单重
                    string strTotal_weight = (GlobalFuncs.GetUnitWeight(rebarLst[i].Item2) * rebarLst[i].Item3 * rebarLst[i].Item4 * 0.01).ToString("0.0");                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_weight; //获取i行j列数据

                    }
                    //string _blcName = "OneGrade";
                    //switch (Grade)
                    //{
                    //    //case "HRB300":

                    //    //    strDiameter = "%%130" + (int)rebarLst[i].Item2;
                    //    //    break;
                    //    //case "HRB335":

                    //    //    strDiameter = "%%131" + (int)rebarLst[i].Item2;
                    //    //    break;
                    //    //case "HRB400":

                    //    //    strDiameter = "%%132" + (int)rebarLst[i].Item2;
                    //    //    break;
                    //    //case "HRB500":

                    //    //    strDiameter = "%%133" + (int)rebarLst[i].Item2;
                    //    //    break;

                    //    case "HRB300":

                    //        strDiameter = "A" + (int)rebarLst[i].Item2;
                    //        break;
                    //    case "HRB335":

                    //        strDiameter = "B" + (int)rebarLst[i].Item2;
                    //        break;
                    //    case "HRB400":

                    //        strDiameter = "C" + (int)rebarLst[i].Item2;
                    //        break;
                    //    case "HRB500":

                    //        strDiameter = "D" + (int)rebarLst[i].Item2;
                    //        break;
                    //    case "HRB650E":

                    //        strDiameter = "D" + (int)rebarLst[i].Item2;
                    //        break;
                    //}
                    //if (rebarLst[i].Item6 != "DE")
                    //{
                        strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item2;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                        //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    //}
                    //else
                    //{
                    //    strDiameter = "  " + (int)rebarLst[i].Item2;
                    //    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    //    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string _blcName = "650";
                    //    string _blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    //}
                }
                for (int i = 1; i < rowNum - 1; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("合计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;

                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;

                    }
                }
                tb.Cells[rebarLst.Count + 1, 0].TextString = con; //获取i行j列数据
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rebarLst.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[rebarLst.Count + 1, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 0, rebarLst.Count + 1, 2));

                tb.Rows[rebarLst.Count + 1].Height = 7 * scale;
                tb.Cells[rebarLst.Count + 1, 3].TextString = volum.ToString("0.0"); //获取i行j列数据
                tb.Cells[rebarLst.Count + 1, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rebarLst.Count + 1, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rebarLst.Count + 1, 3].Contents[0].Rotation = 0;
                tb.Cells[rebarLst.Count + 1, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[rebarLst.Count + 1, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 3, rebarLst.Count + 1, colNum - 1));
             


                #region 列单元格合并
                if (headName.Contains("合计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = rebarLst[0].Item2.ToString();
                    for (int i = 0; i < rebarLst.Count; ++i)
                    {
                        if (rebarLst[i].Item2.ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = rebarLst[i].Item2.ToString();

                        }
                        if (i == rebarLst.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion


                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

            }
        }


        public static void DrawBeamMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<string,  eDB, int, double, string, string>> rebarLst, List<string> headName, int count, double volumn,
     int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale, string Grade = "HRB300", string MainGrade = "HRB300", string mainDB = "", string concrete_no = "C35")
        {
            #region 数据合并
            // 数据合并
            Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
            for (int i = 0; i < rebarLst.Count; ++i)
            {
                string strNo = rebarLst[i].Item2.ToString();
                if (dic.Count == 0)
                {
                    List<int> list = new List<int>();
                    list.Add(i);
                    dic.Add(strNo, list);
                }
                else
                {
                    if (!dic.ContainsKey(strNo))
                    {
                        List<int> list = new List<int>();
                        list.Add(i);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        List<int> list = new List<int>();
                        dic.TryGetValue(strNo, out list);
                        list.Add(i);
                        dic[strNo] = list;
                    }
                }
            }
            dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
            #endregion
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                int rowNum = 1 + dic.Count + 1;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 0)
                        tb.MergeCells(CellRange.Create(tb, 0, 0, 0, 1));
                }
                tb.Rows[0].Height = 8 * scale;

                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 4)
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                    else if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 12 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 18 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }
                #region 表格添加数据
                int index = 0;
                double allWeight = 0;
                foreach (KeyValuePair<string, List<int>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    // 设置表数据
                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = rebarLst[pr.Value[i]].Item2;                         // 直径
                        totallength += rebarLst[pr.Value[i]].Item3 * rebarLst[pr.Value[i]].Item4;

                    }
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.01 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    tb.Cells[index + 1, 1].TextString = "Ф" + (int)diameter; //获取i行j列数据
                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight * count).ToString("0.0"); //获取i行j列数据   
                    allWeight += totalWeight * count;
                    string strDiameter = "Ф" + (int)diameter;
                    switch (Grade)
                    {                      
                        case "HRB300":
                            strDiameter = "A" + (int)diameter;
                            break;
                        case "HRB335":
                            strDiameter = "B" + (int)diameter;
                            break;
                        case "HRB400":
                            strDiameter = "C" + (int)diameter;
                            break;
                        case "HRB500":
                            strDiameter = "D" + (int)diameter;
                            break;
                        case "HRB500E":
                            strDiameter = "D" + (int)diameter;
                            break;
                        case "HRB600E":
                            strDiameter = "E" + (int)diameter;
                            break;
                        case "HRB650E":
                            strDiameter = "F" + (int)diameter;
                            break;
                        case "HRB700E":
                            strDiameter = "G" + (int)diameter;
                            break;
                    }
                    string strMainDiameter = "D";
                    switch (MainGrade)
                    {                        
                        case "HRB300":
                            strMainDiameter = "A";
                            break;
                        case "HRB335":
                            strMainDiameter = "B";
                            break;
                        case "HRB400":
                            strMainDiameter = "C";
                            break;
                        case "HRB500":
                            strMainDiameter = "D";
                            break;
                        case "HRB500E":
                            strMainDiameter = "D";
                            break;
                        case "HRB600E":
                            strMainDiameter = "E";
                            break;
                        case "HRB650E":
                            strMainDiameter = "F";
                            break;
                        case "HRB700E":
                            strMainDiameter = "G";
                            break;
                        default:
                            strMainDiameter = "D";
                            break;
                    }
                   
                    tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                    if (mainDB.ToString().Contains(diameter.ToString()))
                    {
                        strDiameter = strMainDiameter + (int)diameter;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                        //string path = Extensions.curAppPath + "HRB650E.dwg";
                        ////string _blcName = "650";
                        //string _blcName = "HRB650E";
                        //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    }
                    else
                    {
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    }
                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, 1, 0, dic.Count, 0));
                tb.MergeCells(CellRange.Create(tb, 1, 2, dic.Count, 2));
                tb.Cells[1, 4].TextString = allWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, dic.Count, 4));
              

                tb.Cells[1 + dic.Count, 0].TextString = "混凝土"; //获取i行j列数据
                tb.Cells[1 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 0].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 0, 2 + dic.Count, 1));

                tb.Cells[1 + dic.Count, 1].TextString = concrete_no; //获取i行j列数据
                tb.Cells[1 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 1].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 1].Contents[0].TextStyleId = id;

                tb.Cells[1 + dic.Count, 2].TextString = "m³"; //获取i行j列数据
                tb.Cells[1 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 2].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 2].Contents[0].TextStyleId = id;


                tb.Cells[1 + dic.Count, 3].TextString = (count * volumn).ToString("0.0"); //获取i行j列数据
                tb.Cells[1 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1 + dic.Count, 3].Contents[0].Rotation = 0;
                tb.Cells[1 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1 + dic.Count, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));

               
                #endregion



                #region 列单元格合并

                #endregion
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }


        #endregion

        public static void DrawPierRebarTable(Database db, ref Extents2d ext, Point3d startPoint, PierPara pierPara,List<Tuple<string, eDB, int, double, string, string>> rebarLst, List<string> headName,
     int rowNum, int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale,double volum= 0, string con = "C50混凝土(m³)")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                ObjectId gjGradeId = st["SRB.tssdeng"];
                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
    
                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[0].Height = 10 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (headName.Contains("大样"))
                    {
                        if (i < 2)
                            tb.Columns[i].Width = 10 * scale;
                        else if (i > 2)
                            tb.Columns[i].Width = 18 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                    else
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 16 * scale;
                       else if (i <= 2)
                            tb.Columns[i].Width = 13 * scale;
                        else
                            tb.Columns[i].Width = 20 * scale;
                    }
                }
                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 5.6 * scale;
                }
                for (int i = 0; i < rebarLst.Count; i++)
                {
                    // 设置表数据    
                    string strNo = rebarLst[i].Item1.ToString();                                     // 钢筋编号
                    string strDiameter = "Ф" + (int)rebarLst[i].Item2;                         // 直径
              
                    string strLength = rebarLst[i].Item5 + "\r    ";                             // 单根长
                    string strNum = rebarLst[i].Item3.ToString();                                // 数量
                    string strTotal_length = (rebarLst[i].Item3* rebarLst[i].Item4 * 0.01).ToString("0.0");                 // 总长
                    string strSingle_weight = GlobalFuncs.GetUnitWeight(rebarLst[i].Item2).ToString("0.000");               // 单重
                    string strTotal_weight = (GlobalFuncs.GetUnitWeight(rebarLst[i].Item2) * rebarLst[i].Item3 * rebarLst[i].Item4 * 0.01).ToString("0.0");                 // 总重
                    if (headName.Contains("大样"))
                    {
                        tb.Cells[i + 1, 0].TextString =  pierPara.name+"墩"+pierPara.Location; //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 8].TextString = strTotal_weight; //获取i行j列数据
                    }
                    else
                    {
                        tb.Cells[i + 1, 0].TextString = pierPara.name+"墩"+pierPara.Location; //获取i行j列数据
                        //tb.Cells[i + 1, 1].TextString = (pierPara.pier_height*100).ToString("0.0"); //获取i行j列数据
                        tb.Cells[i + 1, 1].TextString = strNo; //获取i行j列数据
                        tb.Cells[i + 1, 2].TextString = " "; //获取i行j列数据
                        tb.Cells[i + 1, 3].TextString = strLength; //获取i行j列数据
                        tb.Cells[i + 1, 4].TextString = strNum; //获取i行j列数据
                        tb.Cells[i + 1, 5].TextString = strTotal_length; //获取i行j列数据
                        tb.Cells[i + 1, 6].TextString = strSingle_weight; //获取i行j列数据
                        tb.Cells[i + 1, 7].TextString = strTotal_weight; //获取i行j列数据

                    }

                    //if (rebarLst[i].Item6 != "DE")
                    //{
                        strDiameter = rebarLst[i].Item6 + (int)rebarLst[i].Item2;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width +  tb.Columns[2].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                        //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    //}
                    //else
                    //{
                    //    strDiameter = "  " + (int)rebarLst[i].Item2;
                    //    Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width + tb.Columns[2].Width + tb.Columns[3].Width * 0.5, -tb.Rows[0].Height - rowH * scale * i - rowH * scale * 0.5);
                    //    //TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid);
                    //    TextPloter.AddDBText(db,ptGJGrade, ref ext, strDiameter, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");

                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string _blcName = "650";
                    //    string _blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    //}
               
                }

                for (int i = 1; i < rowNum-1; ++i)
                {
                    tb.Rows[i].Height = rowH * scale;
                    int num = colNum;
                    if (headName.Contains("合计(kg)"))
                        num = colNum - 1;
                    for (int j = 0; j < num; ++j)
                    {
                        tb.Cells[i, j].Contents[0].TextHeight = 2.5 * scale;
                        if (headName.Contains("大样"))
                        {
                            if (j > 2 && j != 4)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        else
                        {
                            if (j > 1 && j != 3)
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                            else
                                tb.Cells[i, j].Alignment = CellAlignment.MiddleCenter;
                        }
                        tb.Cells[i, j].Contents[0].Rotation = 0;
                        tb.Cells[i, j].Borders.Horizontal.Margin = 2 * scale;
                        if (j == 1)
                        {
                            //tb.Cells[i, j].Contents[0].TextStyleId = gjGradeId;
                        }
                        else
                            tb.Cells[i, j].Contents[0].TextStyleId = id;

                    }
                }




                //tb.Cells[rebarLst.Count + 1, 0].TextString = "钢筋连接器"; //获取i行j列数据
                //tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 1, 0].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 1, 0].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 0, rebarLst.Count + 1, 1));
                //tb.Rows[rebarLst.Count + 1].Height = 7 * scale;

                //tb.Cells[rebarLst.Count + 1, 2].TextString = " "; //获取i行j列数据
                //tb.Cells[rebarLst.Count + 1, 2].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 1, 2].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 1, 2].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 1, 2].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 1, 2].Contents[0].TextStyleId = id;
                //string maindia ="";
                //string strMainDiameter = "D";
                //switch (pierPara.pierRebar.main_reinforcement_grade)
                //{

                //    case "HRB300":
                //        strMainDiameter = "A";
                //        break;
                //    case "HRB335":
                //        strMainDiameter = "B";
                //        break;
                //    case "HRB400":
                //        strMainDiameter = "C";
                //        break;
                //    case "HRB500":
                //        strMainDiameter = "D";
                //        break;
                //    case "HRB500E":
                //        strMainDiameter = "D";
                //        break;
                //    case "HRB600E":
                //        strMainDiameter = "E";
                //        break;
                //    case "HRB650E":
                //        strMainDiameter = "F";
                //        break;
                //    case "HRB700":
                //        strMainDiameter = "G";
                //        break;
                //    default:
                //        strMainDiameter = "A";
                //        break;
                //}
                ////if (pierPara.pierRebar.main_reinforcement_grade != "HRB650E")
                ////{
                //    maindia = strMainDiameter + (int)pierPara.pierRebar.main_reinforcement_diameter;
                //    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width + tb.Columns[2].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * rebarLst.Count - tb.Rows[rebarLst.Count + 1].Height * 0.5);
                //    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                ////}
                ////else
                ////{
                ////    maindia = "  " + (int)pierPara.pierRebar.main_reinforcement_diameter;
                ////    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width + tb.Columns[2].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * rebarLst.Count - tb.Rows[rebarLst.Count + 1].Height * 0.5);
                ////    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                ////    string path = Extensions.curAppPath + "HRB650E.dwg";
                ////    //string _blcName = "650";
                ////    string _blcName = "HRB650E";
                ////    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptMainGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                ////}

                //tb.Cells[rebarLst.Count + 1, 3].TextString = "套"; //获取i行j列数据
                //tb.Cells[rebarLst.Count + 1, 3].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 1, 3].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 1, 3].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 1, 3].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 1, 3].Contents[0].TextStyleId = id;
                ////tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 2, 0, rebarLst.Count + 2, 3));
                //List<Tuple<string, eDB, int, double, string, string>> tuLst= rebarLst.FindAll(o => o.Item6 == strMainDiameter);
                //int divCount = 0;
                //foreach(var item in tuLst)
                //{
                //    divCount += ((int)(item.Item4 * 0.01 / 12)) * item.Item3;
                //}

                //tb.Cells[rebarLst.Count + 1, 4].TextString = divCount.ToString(""); //获取i行j列数据
                //tb.Cells[rebarLst.Count + 1, 4].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 1, 4].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 1, 4].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 1, 4].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 1, 4].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 4, rebarLst.Count + 1, colNum - 1));


                //tb.Cells[rebarLst.Count + 2, 0].TextString = con; //获取i行j列数据
                //tb.Cells[rebarLst.Count + 2, 0].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 2, 0].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 2, 0].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 2, 0].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 2, 0].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 2, 0, rebarLst.Count + 2, 3));

                //tb.Rows[rebarLst.Count + 2].Height = 7 * scale;
                //tb.Cells[rebarLst.Count + 2, 4].TextString = volum.ToString("0.0"); //获取i行j列数据
                //tb.Cells[rebarLst.Count + 2, 4].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[rebarLst.Count + 2, 4].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[rebarLst.Count + 2, 4].Contents[0].Rotation = 0;
                //tb.Cells[rebarLst.Count + 2, 4].Borders.Horizontal.Margin = 2 * scale;
                //tb.Cells[rebarLst.Count + 2, 4].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 2, 4, rebarLst.Count + 2, colNum - 1));

                tb.Cells[rebarLst.Count + 1, 0].TextString = con; //获取i行j列数据
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rebarLst.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[rebarLst.Count + 1, 0].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[rebarLst.Count + 1, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 0, rebarLst.Count + 1, 3));

                tb.Rows[rebarLst.Count + 1].Height = 7 * scale;
                tb.Cells[rebarLst.Count + 1, 4].TextString = volum.ToString("0.0"); //获取i行j列数据
                tb.Cells[rebarLst.Count + 1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rebarLst.Count + 1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rebarLst.Count + 1, 4].Contents[0].Rotation = 0;
                tb.Cells[rebarLst.Count + 1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[rebarLst.Count + 1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, rebarLst.Count + 1, 4, rebarLst.Count + 1, colNum - 1));
                #region 列单元格合并
                if (headName.Contains("合计(kg)"))
                {
                    // 数据排序
                    Dictionary<int, int> dic = new Dictionary<int, int>();
                    int rowIndex = 0;
                    int num = 0;
                    string stDia = rebarLst[0].Item2.ToString();
                    for (int i = 0; i < rebarLst.Count; ++i)
                    {
                        if (rebarLst[i].Item2.ToString() == stDia)
                        {
                            num++;
                        }
                        else
                        {
                            dic.Add(rowIndex, num);
                            num = 1;
                            rowIndex = i;
                            stDia = rebarLst[i].Item2.ToString();

                        }
                        if (i == rebarLst.Count - 1)
                            dic.Add(rowIndex, num);
                    }

                    // 列单元格合并
                    int topRow = 1;

                    List<CellRange> cellList = new List<CellRange>();

                    foreach (KeyValuePair<int, int> pr in dic)
                    {
                        double weight = 0.0;
                        for (int i = 0; i < pr.Value; ++i)
                        {
                            weight += double.Parse(tb.Cells[i + topRow, tb.Columns.Count - 2].Value.ToString());
                        }

                        tb.Cells[topRow, tb.Columns.Count - 1].TextString = weight.ToString(); //获取i行j列数据
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].Rotation = 0;
                        tb.Cells[topRow, tb.Columns.Count - 1].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[topRow, tb.Columns.Count - 1].Contents[0].TextStyleId = id;

                        CellRange range = CellRange.Create(tb, topRow, tb.Columns.Count - 1, topRow + pr.Value - 1, tb.Columns.Count - 1);
                        cellList.Add(range);
                        topRow += pr.Value;
                    }
                    foreach (CellRange range in cellList)
                    {
                        tb.MergeCells(range);
                    }
                }
                #endregion
                tb.MergeCells(CellRange.Create(tb, 1, 0, rowNum-1-1, 0));
                //tb.MergeCells(CellRange.Create(tb, 1, 1, rowNum - 1-2, 1));

                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();

            }
        }


        public static void DrawPierMaterialsTable(Database db, ref Extents2d ext, Point3d startPoint, List<Tuple<PierPara, List<Tuple<string, eDB, int, double, string, string>>>>  tuLst, List<string> headName,
    int colNum, ref double tbHeight, ref double tbWidth, string txtStyle, double scale, double volumTotal = 0)
        {
            #region 数据合并
            // 数据合并
            Dictionary<eDB, List<Tuple<string, eDB, int, double, string, string>>> dic = new Dictionary<eDB, List<Tuple<string, eDB, int, double, string, string>>>();
           
            int divCount = 0;
            int divCountInner = 0;
            string strDiameter = "D";
            string strMainDiameter = "D";
            switch (tuLst[0].Item1.pierRebar.reinforcement_grade)
            {

                case "HRB300":
                    strDiameter = "A";
                    break;
                case "HRB335":
                    strDiameter = "B";
                    break;
                case "HRB400":
                    strDiameter = "C";
                    break;
                case "HRB500":
                    strDiameter = "D";
                    break;
                case "HRB500E":
                    strDiameter = "D";
                    break;
                case "HRB600E":
                    strDiameter = "E";
                    break;
                case "HRB650E":
                    strDiameter = "F";
                    break;
                case "HRB700":
                    strDiameter = "G";
                    break;
                default:
                    strDiameter = "A";
                    break;
            }
            switch (tuLst[0].Item1.pierRebar.main_reinforcement_grade)
            {

                case "HRB300":
                    strMainDiameter = "A";
                    break;
                case "HRB335":
                    strMainDiameter = "B";
                    break;
                case "HRB400":
                    strMainDiameter = "C";
                    break;
                case "HRB500":
                    strMainDiameter = "D";
                    break;
                case "HRB500E":
                    strMainDiameter = "D";
                    break;
                case "HRB600E":
                    strMainDiameter = "E";
                    break;
                case "HRB650E":
                    strMainDiameter = "F";
                    break;
                case "HRB700":
                    strMainDiameter = "G";
                    break;
                default:
                    strMainDiameter = "A";
                    break;
            }

            foreach (Tuple<PierPara, List<Tuple<string, eDB, int, double, string, string>>> item in tuLst)
            {
                List< Tuple<string, eDB, int, double, string, string>> list = new List<Tuple<string, eDB, int, double, string, string>>();
                for (int i = 0; i < item.Item2.Count; ++i)
                {
                    eDB strNo = item.Item2[i].Item2;
                    if (dic.Count == 0)
                    {
                        //Tuple<string, eDB, int, double, string, string> tu = new Tuple<string, eDB, int, double, string, string>(item.Item2[i]);
                        list.Add(item.Item2[i]);
                        dic.Add(strNo, list);
                    }
                    else
                    {
                        if (!dic.ContainsKey(strNo))
                        {
                            list = new List<Tuple<string, eDB, int, double, string, string>>();
                            list.Add(item.Item2[i]);
                            dic.Add(strNo, list);
                        }
                        else
                        {
                            List< Tuple < string, eDB, int, double, string, string>> lstDB = new List<Tuple<string, eDB, int, double, string, string>> (); 
                            dic.TryGetValue(strNo, out lstDB);
                            //Tuple<int, Tuple<int, eDB, int, double, string>> tu = new Tuple<int, Tuple<int, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                            lstDB.Add(item.Item2[i]);
                            dic[strNo] = lstDB;
                        }
                    }
                }

                if (item.Item1.pierRebar.main_reinforcement_diameter == item.Item1.pierRebar.inner_main_reinforcement_diameter)
                {
                    List<Tuple<string, eDB, int, double, string, string>> tuLst0 = item.Item2.FindAll(o => o.Item6 == strMainDiameter);

                    foreach (var item0 in tuLst0)
                    {
                        divCount += ((int)(item0.Item4 * 0.01 / 12)) * item0.Item3;
                    }
                }
                else
                {
                    List<Tuple<string, eDB, int, double, string, string>> tuLst0 = item.Item2.FindAll(o => o.Item6 == strMainDiameter&&o.Item2== item.Item1.pierRebar.main_reinforcement_diameter);

                    foreach (var item0 in tuLst0)
                    {
                        divCount += ((int)(item0.Item4 * 0.01 / 12)) * item0.Item3;
                    }

                    List<Tuple<string, eDB, int, double, string, string>> tuLst1 = item.Item2.FindAll(o => o.Item6 == strMainDiameter && o.Item2 == item.Item1.pierRebar.inner_main_reinforcement_diameter);

                    foreach (var item0 in tuLst1)
                    {
                        divCountInner += ((int)(item0.Item4 * 0.01 / 12)) * item0.Item3;
                    }
                }
            }
            dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
            #endregion
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                //int rowNum = 1 + dic.Count + 2;
                //if(divCountInner>0)
                //    rowNum = 1 + dic.Count + 3;
                int rowNum = 1 + dic.Count + 3;
                if (divCountInner > 0)
                    rowNum = 1 + dic.Count + 4;
               
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                // 设置表头
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 0)
                        tb.MergeCells(CellRange.Create(tb, 0, 0, 0, 1));
                }
                tb.Rows[0].Height = 6.5 * scale;
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 22 * scale;
                    }
                    else if (i == 1 || i == 2)
                    {
                        tb.Columns[i].Width = 12 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 22 * scale;
                    }
                }

                for (int i = 1; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 5.6 * scale;
                }


                #region 表格添加数据
                int index = 0;
                double allWeight = 0;
               
                foreach (KeyValuePair<eDB, List<Tuple<string, eDB, int, double, string, string>>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    // 设置表数据

                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = pr.Key;                         // 直径
                        totallength += (pr.Value[i].Item3 * pr.Value[i].Item4);

                    }
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.01 * weight;
                    tb.Cells[index + 1, 0].TextString = strNo; //获取i行j列数据
                    string vdia = "Ф" + (int)diameter;
                    //if (pr.Key != tuLst[0].Item1.spiral_reinforcement_diameter)
                    //{
                    tb.Cells[index + 1, 1].TextString = " "; //获取i行j列数据
                    if ((pr.Key == tuLst[0].Item1.pierRebar.main_reinforcement_diameter|| pr.Key == tuLst[0].Item1.pierRebar.inner_main_reinforcement_diameter) )
                    {
                        //vdia = tuLst[0].Item4 + (int)diameter;
                        vdia = strMainDiameter + (int)diameter;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, vdia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                        //string path = Extensions.curAppPath + "HRB650E.dwg";
                        ////string _blcName = "650";
                        //string _blcName = "HRB650E";
                        //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptGJGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    }
                    else
                    {
                       
                        vdia = strDiameter + (int)diameter;
                        Point3d ptGJGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * index - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptGJGrade, ref ext, vdia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    }

                    tb.Cells[index + 1, 2].TextString = unit; //获取i行j列数据
                    tb.Cells[index + 1, 3].TextString = (totalWeight).ToString("0.0"); //获取i行j列数据   
                    allWeight += totalWeight;
                    for (int i = 0; i < colNum - 1; i++)
                    {
                        tb.Cells[index + 1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[index + 1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[index + 1, i].Contents[0].Rotation = 0;
                        tb.Cells[index + 1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[index + 1, i].Contents[0].TextStyleId = id;
                    }
                    index++;
                }
                tb.MergeCells(CellRange.Create(tb, 1, 0, dic.Count, 0));
                tb.MergeCells(CellRange.Create(tb, 1, 2, dic.Count, 2));
                tb.Cells[1, 4].TextString = allWeight.ToString("0.0"); //获取i行j列数据
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Borders.Horizontal.Margin = 2 * scale;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, dic.Count, 4));

                if (divCountInner == 0)
                {
                    tb.Cells[1 + dic.Count, 0].TextString = "钢筋连接器"; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 0].Contents[0].TextStyleId = id;

                    tb.Cells[1 + dic.Count, 1].TextString = " "; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 1].Contents[0].TextStyleId = id;
                    string maindia = " " + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;

                    //if (tuLst[0].Item1.pierRebar.main_reinforcement_grade != "HRB650E")
                    //{
                        maindia = strMainDiameter + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;
                        Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //}
                    //else
                    //{
                    //    maindia = "  " + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;
                    //    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                    //    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string _blcName = "650";
                    //    string _blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptMainGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    //}

                    tb.Cells[1 + dic.Count, 2].TextString = "套"; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 2].Contents[0].TextStyleId = id;


                    tb.Cells[1 + dic.Count, 3].TextString = (divCount).ToString(); //获取i行j列数据
                    tb.Cells[1 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));


                    tb.Cells[2 + dic.Count, 0].TextString = "劲性骨架"; //获取i行j列数据
                    tb.Cells[2 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[2 + dic.Count, 1].TextString ="Q235"; //获取i行j列数据
                    tb.Cells[2 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[2 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                    tb.Cells[2 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 2].Contents[0].TextStyleId = id;


                    tb.Cells[2 + dic.Count, 3].TextString = (volumTotal*35).ToString("0.0"); //获取i行j列数据
                    tb.Cells[2 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 3, 2 + dic.Count, 4));



                    tb.Cells[3 + dic.Count, 0].TextString = "混凝土"; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[3 + dic.Count, 1].TextString = tuLst[0].Item1.pierRebar.concrete_no; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[3 + dic.Count, 2].TextString = "m³"; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 2].Contents[0].TextStyleId = id;


                    tb.Cells[3 + dic.Count, 3].TextString = (volumTotal).ToString("0.0"); //获取i行j列数据
                    tb.Cells[3 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 3 + dic.Count, 3, 3 + dic.Count, 4));
                }
                else
                {
                    tb.Cells[1 + dic.Count, 0].TextString = "钢筋连接器"; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 0, 2 + dic.Count, 0));

                    tb.Cells[1 + dic.Count, 1].TextString = " "; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 1].Contents[0].TextStyleId = id;
                    string maindia = " " + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;

                    //if (tuLst[0].Item1.pierRebar.main_reinforcement_grade != "HRB650E")
                    //{
                        maindia = strMainDiameter + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;
                        Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //}
                    //else
                    //{
                    //    maindia = "  " + (int)tuLst[0].Item1.pierRebar.main_reinforcement_diameter;
                    //    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * dic.Count - tb.Rows[1].Height * 0.5);
                    //    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string _blcName = "650";
                    //    string _blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptMainGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    //}

                    tb.Cells[1 + dic.Count, 2].TextString = "套"; //获取i行j列数据
                    tb.Cells[1 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 2].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 2, 2 + dic.Count, 2));

                    tb.Cells[1 + dic.Count, 3].TextString = (divCount).ToString(); //获取i行j列数据
                    tb.Cells[1 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[1 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[1 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 1 + dic.Count, 3, 1 + dic.Count, 4));


                    tb.Cells[2 + dic.Count, 1].TextString = " "; //获取i行j列数据
                    tb.Cells[2 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 1].Contents[0].TextStyleId = id;
                    maindia = " " + (int)tuLst[0].Item1.pierRebar.inner_main_reinforcement_diameter;

                    //if (tuLst[0].Item1.pierRebar.main_reinforcement_grade != "HRB650E")
                    //{
                        maindia = strMainDiameter + (int)tuLst[0].Item1.pierRebar.inner_main_reinforcement_diameter;
                        ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * (dic.Count + 1) - tb.Rows[1].Height * 0.5);
                        TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //}
                    //else
                    //{
                    //    maindia = "  " + (int)tuLst[0].Item1.pierRebar.inner_main_reinforcement_diameter;
                    //    Point3d ptMainGrade = startPoint.C3D(tb.Columns[0].Width + tb.Columns[1].Width * 0.5, -tb.Rows[0].Height - tb.Rows[1].Height * (dic.Count+1) - tb.Rows[1].Height * 0.5);
                    //    TextPloter.AddDBText(db,ptMainGrade, ref ext, maindia, scale, 2.5, "SRB.tssdeng", 0, TextHorizontalMode.TextCenter, TextVerticalMode.TextVerticalMid, "H细线");
                    //    string path = Extensions.curAppPath + "HRB650E.dwg";
                    //    //string _blcName = "650";
                    //    string _blcName = "HRB650E";
                    //    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", ptMainGrade.C3D(), ref ext, scale * 0.85, 0, true, false);
                    //}




                    tb.Cells[2 + dic.Count, 3].TextString = (divCountInner).ToString(); //获取i行j列数据
                    tb.Cells[2 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[2 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[2 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 2 + dic.Count, 3, 2 + dic.Count, 4));

                    tb.Cells[3 + dic.Count, 0].TextString = "劲性骨架"; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[3 + dic.Count, 1].TextString = "Q235"; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[3 + dic.Count, 2].TextString = "kg"; //获取i行j列数据
                    tb.Cells[3 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 2].Contents[0].TextStyleId = id;


                    tb.Cells[3 + dic.Count, 3].TextString = (volumTotal*35).ToString("0.0"); //获取i行j列数据
                    tb.Cells[3 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[3 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[3 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 3 + dic.Count, 3, 3 + dic.Count, 4));

                    tb.Cells[4 + dic.Count, 0].TextString = "混凝土"; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 0].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 0].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 0].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 0, 4 + dic.Count, 1));

                    tb.Cells[4 + dic.Count, 1].TextString = tuLst[0].Item1.pierRebar.concrete_no; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 1].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 1].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 1].Contents[0].TextStyleId = id;

                    tb.Cells[4 + dic.Count, 2].TextString = "m³"; //获取i行j列数据
                    tb.Cells[4 + dic.Count, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 2].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 2].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 2].Contents[0].TextStyleId = id;


                    tb.Cells[4 + dic.Count, 3].TextString = (volumTotal).ToString("0.0"); //获取i行j列数据
                    tb.Cells[4 + dic.Count, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4 + dic.Count, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4 + dic.Count, 3].Contents[0].Rotation = 0;
                    tb.Cells[4 + dic.Count, 3].Borders.Horizontal.Margin = 2 * scale;
                    tb.Cells[4 + dic.Count, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 4 + dic.Count, 3, 4 + dic.Count, 4));
                }
                #endregion



                #region 列单元格合并

                    #endregion
                    tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);
                tbHeight = tb.Height;
                tbWidth = tb.Width;
                tr.Commit();


            }
        }


    }
}
